service.service('clientService',['requestService',function(requestService){

    var service={};

    var getApiPath=function(path){
        return apiUtil.getPath('/client',path);
    };

    /**
     * 返回客户端
     * @param successCallback
     * @param errorCallback
     */
    service.getClients=function(successCallback,errorCallback){
        requestService.getApi(getApiPath(),{},successCallback,errorCallback);
    };

    /**
     * 注册
     * @param client
     * @param successCallback
     * @param errorCallback
     */
    service.register=function(client,successCallback,errorCallback){
        var slots=[];
        for(var i=parseInt(client.slotStart),len=parseInt(client.slotEnd);i<len;i++) {
            slots.push(i);
        }

        requestService.postApi(getApiPath('/register'),{
            client:client.client,
            host:client.host,
            port:client.port,
            connection:client.connection,
            timeout:client.timeout,
            slots:slots
        },successCallback,errorCallback);
    };

    /**
     * 取消注册
     * @param id
     * @param target
     * @param successCallback
     * @param errorCallback
     */
    service.unregister=function(id,target,successCallback,errorCallback){
        requestService.postApi(getApiPath(id+'/unregister'),{target:target},successCallback,errorCallback);
    };

    /**
     * 注册
     * @param id
     * @param client
     * @param successCallback
     * @param errorCallback
     */
    service.registerRouting=function(id,client,successCallback,errorCallback){
        requestService.postApi(getApiPath(id+"/routing/register"),{
            client:client.client,
            host:client.host,
            port:client.port,
            connection:client.connection,
            timeout:client.timeout
        },successCallback,errorCallback);
    };

    /**
     * 取消注册
     * @param sourceId
     * @param routingId
     * @param successCallabck
     * @param errorCallback
     */
    service.unregisterRouting=function(sourceId,routingId,successCallabck,errorCallback){
        requestService.postApi(getApiPath(sourceId+"/routing/unregister"),{
            routingId:routingId},successCallabck,errorCallback);
    };

    /**
     * info
     * @param id
     * @param successCallback
     * @param errorCallback
     */
    service.getInfo=function(id,successCallback,errorCallback){
        requestService.getApi(getApiPath(id+'/info'),{},successCallback,errorCallback);
    };

    /**
     * mapping
     * @param id
     * @param successCallback
     * @param errorCallback
     */
    service.getSlotMapping=function(id,successCallback,errorCallback){
        requestService.getApi(getApiPath(id+'/mapping'),{},successCallback,errorCallback);
    };

    return service;
}]);